package indi.woniu.security.handler;

import indi.woniu.entity.ResponseEntity;
import indi.woniu.field.StatusCode;
import indi.woniu.utils.Util;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: GaN601
 * @Date: 2021/12/22 15:56
 * @Description:
 */
@Component
public class CustomLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(final HttpServletRequest request, final HttpServletResponse response,
            final Authentication authentication) throws IOException, ServletException {
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().println(
                new ResponseEntity<>(StatusCode.OK, "退出成功", Util.toJsonStr(authentication)));
        
    }
}
